const vscode = require('vscode');

/**
 * @param {vscode.ExtensionContext} context
 */
function activate(context) {
	console.log('Congratulations, your extension "helloworld-minimal-sample" is now active!');
	let disposable = vscode.commands.registerCommand('extension.helloWorld', () => {
		vscode.window.showInformationMessage('Hello World000!');
	});
	context.subscriptions.push(disposable);

	
	myStatusBarItem = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left, 100);
	myStatusBarItem.command = 'extension.helloWorld';
	myStatusBarItem.text = `00000`;
	myStatusBarItem.show();
	context.subscriptions.push(myStatusBarItem);


	//context.subscriptions.push(vscode.window.onDidChangeActiveTextEditor(updateStatusBarItem));
	//context.subscriptions.push(vscode.window.onDidChangeTextEditorSelection(updateStatusBarItem));
	//updateStatusBarItem();
	/*	*/
	let disposable1 = vscode.commands.registerCommand('todolist.helloWorld', () => {
		vscode.window.showInformationMessage('Hello World000!');
	});
	context.subscriptions.push(disposable1);

	let disposable2 = vscode.commands.registerCommand('todolist.helloWorld00', () => {
		vscode.window.showInformationMessage('Hello World000!');
	});
	context.subscriptions.push(disposable2);


	const todolistWebview = new TodoListWebView();

	context.subscriptions.push(
		vscode.window.registerWebviewViewProvider(TodoListWebView.viewId, todolistWebview)
	)

  workspace.workspaceFolders // 所有打开的工作区文件夹
  window.activeTextEditor // 当前打开的文件信息
  workspace.getWorkspaceFolder(uri) // 通过文件uri获取其工作文件夹

}

// this method is called when your extension is deactivated
function deactivate() {}

class TodoListWebView{
  static viewId = 'todolist-view';
  resolveWebviewView(webviewView) {
    webviewView.webview.html = `
      <!DOCTYPE html>
      <html lang="en">
      <head>
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>todolist</title>
      </head>
      <body>
        <div>hello todolist</div>
      </body>
      </html>
    `
  }
}

// setting.json 发生修改时
workspace.onDidChangeConfiguration((event) => {
  // 判断哪个文件夹发生了配置修改
  workspace.workspaceFolders.forEach(element => {
    if (event.affectsConfiguration("配置名称", element)) {
      workspace.getConfiguration("配置名称", element)
    }
  });
})

module.exports = {
	activate,
	deactivate,
	TodoListWebView
}
